import Vue from 'vue'
import VueRouter from 'vue-router'

const _import =
  process.env.NODE_ENV === 'development'
    ? path => require('@/views/' + path).default // 全部加载（dev环境使用）
    : path => () => import('@/views/' + path) // 按需加载（build时使用）

Vue.use(VueRouter)

/**
 * 路由配置说明：
 * - 按模块区分，如home之类的
 * - keepAlive 当前页面是否缓存（返回不刷新）
 * - body 背景色 目前支持的class为  g4(灰色)  默认是白色
 * - footer 目前可配置
 *   · show 表示是否显示底部导航
 * - head 目前可配置：
 *   · title(页面标题)
 *   · show(是否显示公共头)
 *   · shoowBack(是否显示返回按钮)
 *   · back(返回上一页的方法，-1就是直接回到上一页，可以传对应页面的方法名称，这样公共头部会触发对应的方法)
 *   · backUrl 如果当前页面是直接进来的，go-1回不去，就会使用backUrl的名称。如果该字段为空，自动回到对应的根页面
 */

export default new VueRouter({
  routes: [
    { path: '', redirect: '/home/index', meta: { footer: { show: true } } },
    {
      path: '/home/',
      component: _import('Home/HomeBase'),
      redirect: '/home/index',
      children: [
        {
          path: 'index',
          name: 'HomeIndex',
          component: _import('Home/Index/Index'),
          meta: {
            footer: { show: true },
            keepAlive: true,
            body: 'f7',
            head: { title: '首页', showBack: false, show: false, back: -1, backUrl: '' }
          }
        },
        {
          path: 'login',
          name: 'HomeLogin',
          component: _import('Home/Login/Login'),
          meta: {
            footer: { show: false },
            keepAlive: true,
            body: '',
            head: { title: '登录', showBack: false, show: false, back: -1, backUrl: '' }
          }
        },
        {
          path: 'registered',
          name: 'Registered',
          component: _import('Home/Registered/Registered'),
          meta: {
            footer: { show: false },
            keepAlive: true,
            body: '',
            head: { title: '注册', showBack: false, show: false, back: -1, backUrl: '' }
          }
        },
        {
          path: 'goods',
          name: 'GoodsDetail',
          component: _import('Home/GoodsDetail/GoodsDetail'),
          meta: {
            footer: { show: false },
            keepAlive: false,
            body: 'f7',
            head: { title: '商品详情', showBack: true, show: true, back: -1, backUrl: '' }
          }
        },
        {
          path: 'upgrade',
          name: 'Upgrade',
          component: _import('Home/Upgrade/Upgrade'),
          meta: {
            footer: { show: true },
            keepAlive: false,
            body: '',
            head: { title: '我要送礼', showBack: true, show: true, back: -1, backUrl: '' }
          }
        },
        {
          path: 'cart',
          name: 'Cart',
          component: _import('Home/Cart/Cart'),
          meta: {
            footer: { show: true },
            keepAlive: false,
            body: 'f7',
            head: { title: '购物车', showBack: false, show: false, back: -1, backUrl: '' }
          }
        },
        {
          path: 'receive',
          name: 'Receive',
          component: _import('Home/Receive/Receive'),
          meta: {
            footer: { show: false },
            keepAlive: false,
            body: '',
            head: { title: '礼品区', showBack: false, show: false, back: -1, backUrl: '' }
          }
        },
        {
          path: 'article',
          name: 'Article',
          component: _import('Home/Article/Article'),
          meta: {
            footer: { show: false },
            keepAlive: false,
            body: 'f7',
            head: { title: '', showBack: false, show: false, back: -1, backUrl: '' }
          }
        }
      ]
    },
    {
      path: '/member/',
      component: _import('Member/MemberBase'),
      redirect: '/member/index',
      children: [
        {
          path: 'recommend',
          name: 'Recommend',
          component: _import('Member/Recommend/Recommend'),
          meta: {
            footer: { show: false },
            keepAlive: false,
            body: '',
            head: { title: '填写推荐人', showBack: false, show: false, back: -1, backUrl: '' }
          }
        },
        {
          path: 'index',
          name: 'MemberIndex',
          component: _import('Member/Index/Index'),
          meta: {
            footer: { show: true },
            keepAlive: false,
            body: 'f7',
            head: { title: '个人中心', showBack: false, show: false, back: -1, backUrl: '' }
          }
        },
        {
          path: 'makeOrder',
          name: 'MakeOrder',
          component: _import('Member/MakeOrder/MakeOrder'),
          meta: {
            footer: { show: false },
            keepAlive: false,
            body: 'f7',
            head: { title: '确认订单', showBack: true, show: true, back: -1, backUrl: '' }
          }
        },
        {
          path: 'payPage',
          name: 'PayPage',
          component: _import('Member/MakeOrder/PayPage'),
          meta: {
            footer: { show: false },
            keepAlive: false,
            body: '',
            head: { title: '提交订单', showBack: true, show: true, back: -1, backUrl: '' }
          }
        },
        {
          path: 'addressForm',
          name: 'AddressForm',
          component: _import('Member/Address/AddressForm'),
          meta: {
            footer: { show: false },
            keepAlive: false,
            body: 'f7',
            head: { title: '添加收货地址', showBack: false, show: false, back: -1, backUrl: '' }
          }
        },
        {
          path: 'addressList',
          name: 'AddressList',
          component: _import('Member/Address/AddressList'),
          meta: {
            footer: { show: false },
            keepAlive: false,
            body: 'f7',
            head: { title: '收货地址', showBack: true, show: true, back: -1, backUrl: '' }
          }
        },
        {
          path: 'setting',
          name: 'MemberSetting',
          component: _import('Member/Setting/Setting'),
          meta: {
            footer: { show: false },
            keepAlive: false,
            body: 'f7',
            head: { title: '设置', showBack: true, show: true, back: -1, backUrl: '' }
          }
        },
        {
          path: 'editPassword',
          name: 'EditPassword',
          component: _import('Member/EditInfo/EditPassword'),
          meta: {
            footer: { show: false },
            keepAlive: false,
            body: '',
            head: { title: '修改登录密码', showBack: true, show: true, back: -1, backUrl: '' }
          }
        },
        {
          path: 'editPayPassword',
          name: 'EditPayPassword',
          component: _import('Member/EditInfo/EditPayPassword'),
          meta: {
            footer: { show: false },
            keepAlive: false,
            body: '',
            head: { title: '修改支付密码', showBack: true, show: true, back: -1, backUrl: '' }
          }
        },
        {
          path: 'editName',
          name: 'EditName',
          component: _import('Member/EditInfo/EditName'),
          meta: {
            footer: { show: false },
            keepAlive: false,
            body: '',
            head: { title: '修改昵称', showBack: true, show: true, back: -1, backUrl: '' }
          }
        },
        {
          path: 'bindMobile',
          name: 'BindMobile',
          component: _import('Member/EditInfo/BindMobile'),
          meta: {
            footer: { show: false },
            keepAlive: false,
            body: '',
            head: { title: '绑定手机号', showBack: true, show: true, back: -1, backUrl: '' }
          }
        },
        {
          path: 'orderList',
          name: 'OrderList',
          component: _import('Member/Order/OrderList'),
          meta: {
            footer: { show: false },
            keepAlive: false,
            body: 'f7',
            head: { title: '订单列表', showBack: true, show: true, back: -1, backUrl: '' }
          }
        },
        {
          path: 'orderDetail',
          name: 'OrderDetail',
          component: _import('Member/Order/OrderDetail'),
          meta: {
            footer: { show: false },
            keepAlive: false,
            body: 'f7',
            head: { title: '订单详情', showBack: true, show: false, back: -1, backUrl: '' }
          }
        },
        {
          path: 'realyName',
          name: 'RealyName',
          component: _import('Member/RealyName/RealyName'),
          meta: {
            footer: { show: false },
            keepAlive: false,
            body: '',
            head: { title: '实名认证', showBack: true, show: true, back: -1, backUrl: '' }
          }
        },
        {
          path: 'manage',
          name: 'Manage',
          component: _import('Member/Manage/Manage'),
          meta: {
            footer: { show: false },
            keepAlive: false,
            body: '',
            head: { title: '管理中心', showBack: false, show: false, back: -1, backUrl: '' }
          }
        },
        {
          path: 'billsFlow',
          name: 'BillsFlow',
          component: _import('Member/BillsFlow/BillsFlow'),
          meta: {
            footer: { show: false },
            keepAlive: false,
            body: 'f7',
            head: { title: '账单明细', showBack: true, show: true, back: -1, backUrl: '' }
          }
        }
      ]
    }
  ]
})
